package com.supermap.dataservice.server.microclimate;

import com.supermap.dataservice.thrid.microclimate.MicroclimateWsdlServiceFactory;
import com.supermap.dataservice.util.JSONUtil;
import com.supermap.dubbo.api.microclimate.MicroclimateDubboService;

import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author xiaolu
 * @date 2018/8/1 下午3:33
 */
public class MicroclimateDubboServiceImpl implements MicroclimateDubboService {

    @Override
    @Deprecated
    public JSONUtil getCROPDataByTime(String stationId, String observeTime, String elementType) {

        StringBuilder sb = new StringBuilder();
        String data = null;
        try {
            data = MicroclimateWsdlServiceFactory.getCROPDataServiceSoap12BindingStub().XXZX_CROP_GetCROPDataByTime(stationId, observeTime, elementType);
        } catch (RemoteException e) {
            e.printStackTrace();
        }

        return assistResultData(sb, data);
    }

    @Override
    public JSONUtil getCROPDataByTimeRange(String stationId, String startTime, String endTime, String elementType, String userName, String password) {

        StringBuilder sb = new StringBuilder();
        String data = null;
        try {
            data = MicroclimateWsdlServiceFactory.getCROPDataServiceSoap12BindingStub().XXZX_CROP_GetCROPDataByTimeRange(stationId, startTime, endTime, elementType, userName, password);
        } catch (RemoteException e) {
            e.printStackTrace();
        }

        return assistResultData(sb, data);
    }

    /**
     * 构造返回数据
     *
     * @param sb
     * @param data
     * @return
     */
    private JSONUtil assistResultData(StringBuilder sb, Object data) {
        JSONUtil result = new JSONUtil();
        if (data == null) {
            result.setCode(400);
            result.setIsSuccess(false);
            result.setMsg("数据获取失败!\n" + sb.toString());
        } else {
            result.setData(data);
        }
        return result;
    }
}
